package com.baidu.mpks.util;

import com.baidu.mpks.exception.BusinessException;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * ********************************************************
 * <p>
 * Copyright (c) 2018 Baidu.com, Inc. All Rights Reserved
 * <p>
 * ********************************************************
 *
 * @date: 2018-12-25
 * @author: licong08
 * @description: Blank
 */
// todo spring Validated
public class ValidationUtil {
    public static void check(String key, int maxLength, String value) {
        if (value != null && value.length() > maxLength) {
            throw new BusinessException(key + "长度不能超过" + maxLength);
        }
    }

    public static String stringFilter(String data) {
        String regEx = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。，、？]";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(data);
        return m.replaceAll("").trim();
    }
}
